﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebNext.Domain.Entities;
using WebNext.Domain.Interfaces;
using WebNext.Domain;

namespace WebNext.DataAccess.Repositories
{
	public class TagsRepository : EntitiesRepository<Tag>, ITagsRepository
	{
		public CultureId CultureId
		{
			get;
			set;
		}

		public TagsRepository(IDatabaseContext databaseContext) : base(databaseContext)
		{
		}

		public bool CheckIfTagNameIsUsed(int id, string name)
		{
			return this.databaseContext.Session.QueryOver<Tag>().Where(t => t.Id != id && t.Name == name && t.CultureId == this.CultureId).RowCount() > 0;
		}

		public bool CheckIfTagCodeIsUsed(int id, string code)
		{
			return this.databaseContext.Session.QueryOver<Tag>().Where(t => t.Id != id && t.Code == code && t.CultureId == this.CultureId).RowCount() > 0;
		}

		public override IEnumerable<Tag> GetAll()
		{
			return this.databaseContext.Session.QueryOver<Tag>().Where(t => t.CultureId == this.CultureId).List();
		}
	}
}
